module WxRide
	
	# The _EditorPage_ class subclasses the StyledTextCtrl
	# control of wxRuby.
	class EditorPage < StyledTextCtrl
		include Wx
		attr_reader :name, :fname
		@@editors = []

		STYLE_DEFAULT = 0
		STYLE_ERROR = 1
		STYLE_COMMENTLINE = 2
		STYLE_POD = 3
		STYLE_NUMBER = 4
		STYLE_WORD = 5
		STYLE_STRING = 6
		STYLE_CHARACTER = 7
		STYLE_CLASSNAME = 8
		STYLE_DEFNAME = 9
		STYLE_OPERATOR = 10
		STYLE_IDENTIFIER = 11
		STYLE_REGEX = 12
		STYLE_GLOBAL = 13
		STYLE_SYMBOL = 14
		STYLE_MODULE_NAME = 15
		STYLE_INSTANCE_VAR = 16
		STYLE_CLASS_VAR = 17
		STYLE_BACKTICKS = 18
		STYLE_DATASECTION = 19
		STYLE_HERE_DELIM = 20
		STYLE_HERE_Q = 21
		STYLE_HERE_QQ = 22
		STYLE_HERE_QX = 23
		STYLE_STRING_Q = 24
		STYLE_STRING_QQ = 25
		STYLE_STRING_QX = 26
		STYLE_STRING_QR = 27
		STYLE_STRING_QW = 28
		STYLE_WORD_DEMOTED = 29
		STYLE_STDIN = 30
		STYLE_STDOUT = 31
		STYLE_STDERR = 40
		STYLE_UPPER_BOUND = 41
	
		# Checks to see if _file_ is currently open as an EditorPage instance.
		# The method returns true if _file_ is open, false otherwise.
		def EditorPage.exist?(file)
			@@editors.each do |ep|
				if ep.name == File.basename(file)
					indx = ep.get_parent.get_page_index(ep)
					ep.get_parent.set_selection(indx)
					return true
				end
			end
				return false
		end
	
		# Opens _file_ in an EditorPage instance.  If _file_ is not provided, then
		# a FileDialog window is opened to get the user's input.  The method
		# returns nil if the user cancels the operation.
		def EditorPage.open(nb,file=nil)
			# If no file name is passed, open a File Dialog box:
			if file.nil?
				file = FileDialog.new(Wx::get_app.get_top_window,"Open file...","","","Ruby Files (*.rb;*.rbw;Rakefile)|*.rb;*.rbw;Rakefile|All Files(*.*)|*.*",FD_OPEN|FD_FILE_MUST_EXIST)
				ret = file.show_modal
				if ret == ID_CANCEL
					return nil
				end
				file = file.get_path()
				if !File.exist?(file)
					i = file.rindex(".")
					if File.exist?(file[0..i-1])
						file = file[0..i-1]
					end
				end
			end
			
			unless EditorPage.exist?(file)
				Dir.chdir(File.dirname(file))
				ep = EditorPage.new(nb)
				@loading = true
				ep.load_file(file)
				ep.set_save_point()
				@loading = false
				ep
			else
				nil
			end
		end
	
		# Exits the program after giving the user the opportunity to save any
		# open, modified files.
		def EditorPage.program_exit()
			modified = []
			@@editors.each do |ep|
				if ep.is_modified?
					modified << ep
				end
			end
			if modified.length > 0
				ret = MessageDialog.new(Wx::get_app.get_top_window,"There are still #{modified.length} unsaved documents, do you wish to save them?","Exit wxRIDE",YES_NO|CANCEL|ICON_QUESTION).show_modal
				if ret == ID_YES
					modified.each do |ep|
						ep.save_file
					end
					true
				elsif ret == ID_NO
					true
				else
					false
				end
			end
			true
		end
	
		# Sets up the EditorPage instance.
		def initialize(*args)
			super
			@name = "Untitled"

			@fname = ""
			
			# Temporary setup area for defining the hashes to be sent to the 
			# set_syntax method.
			indent_string = "5 def class if do elsif else case while for"
			end_string = "5 end"
			
			layout_params = { 'edge_mode' => STC_EDGE_LINE,
				'text_width' => "_99999",
				'tab_width' => 2,
				'use_tabs' => true,
				'tab_indents' => true,
				'backspace_unindents' => true,
				'indentation_guides' => true,
				'indent' => 2,
				'columns' => 80,
				'fold' => "1",
				'fold.compact' => "0",
				'fold.comment' => "1",
				'fold.preprocessor' => "1",
				'statement_indent' => indent_string,
				'statement_end' => end_string,
				'comment.block' => "#~",
				'block.start' => "do",
				'block.end' => "end",
				'braces' => "10" }
			
			color_params = { 'fore_default' => BLACK,
				'back_default' => WHITE,
				'fore_linenumber' => LIGHT_GREY,
				'back_linenumber' => WHITE,
				'fore_indentguide' => LIGHT_GREY }
				
			margin_params = { 'text_width' => [STC_STYLE_LINENUMBER, "_99999"],
				'margin_width' => [1, 0],
				'margin_type' => [1, STC_MARGIN_SYMBOL],
				'margin_mask' => [1, STC_MASK_FOLDERS],
				'margin_width' => [1, 20],
				'margin_sensitive' => [1, 1] }
			
			marker_params = { 'folder' => STC_MARK_PLUS,
				'folder_open' => STC_MARK_MINUS,
				'folder_end' => STC_MARK_EMPTY,
				'folder_midtail' => STC_MARK_EMPTY,
				'folder_openmid' => STC_MARK_EMPTY,
				'folder_sub' => STC_MARK_EMPTY,
				'folder_tail' => STC_MARK_EMPTY,
				'fold_flag' => 16}

			keywords = "__FILE__ and def end in or self unless __LINE__ begin \
defined? ensure module redo super until BEGIN break do false next rescue \
then when END case else for nil retry true while alias class elsif if \
not return undef yield"

			# Set the font.
			set_font(STC_STYLE_DEFAULT)
			
			# Set the syntax (currently only the Ruby syntax is available).
			set_syntax(STC_LEX_RUBY, layout_params, color_params, margin_params,
				marker_params, keywords)
		
			# Add this instance to the list.
			@@editors << self
		
			# Register events.
			evt_stc_marginclick(self.get_id()) {|evt| on_margin_click(evt)}
			evt_stc_savepointreached(self.get_id()) {|evt| on_savepoint_reached(evt)}
			evt_stc_savepointleft(self.get_id()) {|evt| on_savepoint_left(evt)}
			evt_stc_charadded(self.get_id()) {|evt| on_charadded(evt)}
			evt_stc_modified(self.get_id()) {|evt| on_modified(evt)}
			evt_stc_updateui(self.get_id()) {|evt| on_update_ui(evt)}
			evt_stc_do_drop(self.get_id()) {|evt| on_do_drop(evt)}
			evt_stc_key(self.get_id()) {|evt| puts "Received key event, calling on_key()"; on_key(evt)}
		
			evt_find(ID_ANY) {|evt| on_find_dialog(evt)}
			evt_find_next(ID_ANY) {|evt| on_find_dialog(evt)}
			evt_find_replace(ID_ANY) {|evt| on_find_dialog(evt)}
			evt_find_replace_all(ID_ANY) {|evt| on_find_dialog(evt)}
			evt_find_close(ID_ANY) {|evt| on_find_dialog(evt)}
		end
	
		# Sets the font of the editor page.
		# =
		# <b>Parameters:</b>
		# _font_style_:: integer constant representing the style
		# =
		# <b>Returns:</b>
		# Nothing
		def set_font(font_style)
			
			case Wx::PLATFORM
				when "WXMSW"
					face = "Courier New"
					size = 10
				when "WXGTK"
					face = "Bitstream Vera Sans Mono"
					size = 10
				when "WXMAC"
					face = "Monaco"
					size = 12
				end
			
			font = Font.new(size, FONTFAMILY_TELETYPE, NORMAL, NORMAL, false,face)

			self.style_set_font(font_style, font)
		end
		

		# Sets up the editor page syntax.
		# =
		# <b>Parameters:</b>
		# _lexer_:: integer constant representing the lexer type
		# _layout_:: hash containing layout information.  The key/value pairs are:
		#   'edge_mode' => (integer) STC global value
		#   'text_width => (string) ?
		#   'tab_width' => (integer) size of tab spacing
		#   'use_tabs' => (boolean) use tabs?
		#   'tab_indents' => (boolean) tabs indent?
		#   'backspace_unindents' => (boolean) backspace removes indents?
		#   'indentation_guides' => (boolean) show indentation guides?
		#   'indent' => (integer) size of indentation
		#   'columns' => (integer) number of columns
		#   'fold' => (string) allow code folding? "1" - yes, "0" - no
		#   'fold.compact' => (string) "1" - yes, "0" - no
		#   'fold.comment' => (string) "1" - yes, "0" - no
		#   'fold.preprocessor' => (string) "1" - yes, "0" - no
		#   'statement_indent' => (string) indent keywords
		#   'statement_end' => (string) end keywords
		#   'comment.block' => (string) default: "#~"	
		#   'block.start' => (string) word starting off block
		#   'block.end' => (string) word ending block
		#   'braces' => (string) ?
		# _color_:: hash containing color information.  The key/value pairs are:
		#   'fore_default' => (color) default foreground text color
		#   'back_default' => (color) default background text color
		#   'fore_linenumber' => (color) line number text color
		#   'back_linenumber' => (color) line number background color
		#   'fore_indentguide' => (color) indent guide color
		# _margin_:: hash containing margin information.  The key/value pairs are:
		#   'text_width' => (array) two element array
		#   'margin_width' => (array) two element array
		#   'margin_type' => (array) two element array
		#   'margin_mask' => (array) two element array
		#   'margin_width' => (array) two element array
		#   'margin_sensitive' => (array) two element array
		# _marker_:: hash containing marker information.  The key/value pairs are:
		#   'folder' => (integer) STC_MARK_PLUS|STC_MARK_MINUS|STC_MARK_EMPTY
		#   'folder_open' => (integer) STC_MARK_PLUS|STC_MARK_MINUS|STC_MARK_EMPTY 
		#   'folder_end' => (integer) STC_MARK_PLUS|STC_MARK_MINUS|STC_MARK_EMPTY 
		#   'folder_midtail' => (integer) STC_MARK_PLUS|STC_MARK_MINUS|STC_MARK_EMPTY 
		#   'folder_openmid' => (integer) STC_MARK_PLUS|STC_MARK_MINUS|STC_MARK_EMPTY 
		#   'folder_sub' => (integer) STC_MARK_PLUS|STC_MARK_MINUS|STC_MARK_EMPTY 
		#   'folder_tail' => (integer) STC_MARK_PLUS|STC_MARK_MINUS|STC_MARK_EMPTY 
		#   'fold_flag' => (integer) STC_MARK_PLUS|STC_MARK_MINUS|STC_MARK_EMPTY 
		# _keywords_:: (string) list of recognized keywords
		# =
		# <b>Returns:</b>
		# Nothing
		def set_syntax(lexer, layout, color, margin, marker, keywords)
		
			@modified = false
			@in_case = false
			@ws_visible = false
			@eol_visible = false
			
			self.set_edge_mode(layout['edge_mode'])

			# Set up the margins.
			line_num_margin = self.text_width(STC_STYLE_LINENUMBER,
				layout['text_width'])
			self.set_margin_width(0, line_num_margin)

			# Set up the colors.
			self.style_set_foreground(STC_STYLE_DEFAULT, color['fore_default'])
			self.style_set_background(STC_STYLE_DEFAULT, color['back_default'])
			self.style_set_foreground(STC_STYLE_LINENUMBER, color['fore_linenumber'])
			self.style_set_background(STC_STYLE_LINENUMBER, color['back_linenumber'])
			self.style_set_foreground(STC_STYLE_INDENTGUIDE,
				color['fore_indentguide'])

			# Set tabs.
			self.set_tab_width(layout['tab_width'])
			self.set_use_tabs(layout['use_tabs'])
			self.set_tab_indents(layout['tab_indents'])
			self.set_back_space_un_indents(layout['backspace_unindents'])
			self.set_indent(layout['indent'])
			self.set_edge_column(layout['columns'])

			# Define the lexer.
			self.set_lexer(lexer)
			self.style_clear_all
		
			# Load colors.
			self.load_colors
		
			# Define keywords.
			self.set_key_words(0, keywords)

			# Set various other syntax properties.
			self.set_property("fold", layout['fold'])
			self.set_property("fold.compact", layout['fold.compact'])
			self.set_property("fold.comment", layout['fold.comment'])
			self.set_property("fold.preprocessor", layout['fold.preprocessor'])
		
			self.set_property("statement.indent", layout['statement_indent'])
			self.set_property("statement.end",layout['statement_end'])
			self.set_property("block.start", layout['block.start'])
			self.set_property("block.end", layout['block.end'])
		
			self.set_back_space_un_indents(layout['backspace_unindents'])
			self.set_indentation_guides(layout['indentation_guides'])
			self.set_property("comment.block", layout['comment.block'])
			self.set_property("braces", layout['braces'])

			self.set_margin_width(
				margin['margin_width'][0], margin['margin_width'][1])	
			self.set_margin_type(margin['margin_type'][0], margin['margin_type'][1])
			self.set_margin_mask(margin['margin_mask'][0], margin['margin_mask'][1])
			self.set_margin_width(
				margin['margin_width'][0], margin['margin_width'][0])

			self.marker_define(STC_MARKNUM_FOLDER, marker['folder'])
			self.marker_define(STC_MARKNUM_FOLDEROPEN, marker['folder_open'])
			self.marker_define(STC_MARKNUM_FOLDEREND, marker['folder_end'])
			self.marker_define(STC_MARKNUM_FOLDERMIDTAIL, marker['folder_midtail'])
			self.marker_define(STC_MARKNUM_FOLDEROPENMID, marker['folder_openmid'])
			self.marker_define(STC_MARKNUM_FOLDERSUB, marker['folder_sub'])
			self.marker_define(STC_MARKNUM_FOLDERTAIL, marker['folder_tail'])
			self.set_fold_flags(marker['fold_flag'])

			self.set_margin_sensitive(
				margin['margin_sensitive'][0], margin['margin_sensitive'][1])
		
		end
	
		# Loads the file specified by _fname_.
		def load_file(fname)
			@name = get_file_name(fname)
			@fname = fname
			buffer = IO.read(@fname)
			data = ""
			buffer.each_line do |line|
				if line[0].chr == " "
					loop do
						i = line.index(" ")
						if i.nil?
							break
						elsif line[i+1].chr != " "
							break
						end
						line[i..i+1] = "\t"
					end
				end
				data += line
			end
			self.set_text(data)
		end
	
		def save_file(saveas=false)
			unless saveas
				return unless self.is_modified?
			end
			if @fname == ""
				get_save_file()
			elsif saveas
				if get_saveas_file() == ID_CANCEL
					return
				end
			end
			return if @fname == ""
			if ($config[:use_tabs].nil? ? true : $config[:use_tabs])
				super(@fname)
			else
				buffer = self.get_text()
				data = ""
				buffer.each_line do |line|
					loop do
						i = line.index("\t")
						if i.nil?
							break
						end
						if line[i+1] != nil
							if (line[i+1].chr == "\t" || line[i+1].chr != " ")
								line[i] = "  "
							else
								break
							end
						else
							break
						end
					end
					data += line
				end
				File.open(@fname,"wb") do |fh|
					fh.print(data)
				end
			end
			self.set_save_point()
			nb = self.get_parent
			page = nb.get_page_index(self)
			nb.set_page_text(page,@name)
		end
	
		def close
			if self.is_modified?
				ret = MessageDialog.new(self,"#{self.name} has not been saved yet, do you wish to save?","wxRIDE Question",YES_NO|CANCEL|ICON_QUESTION).show_modal
				if ret == ID_CANCEL
					return false
				elsif ret == ID_YES
					save_file
				end
			end
			@@editors.delete(self)
		end
	
		def is_modified?
			@modified
		end
	
		def load_colors
			DEFAULT_FORMAT.each_line do |line|
				if line[0].chr != "#"
					nmbr, spec = line.split("=")
					self.style_set_spec(nmbr.to_i,spec)
					if spec.index("eolfilled")
						self.style_set_eol_filled(nmbr.to_i,true)
					end
					if spec.index("bold")
						if !spec.index("notbold")
							self.style_set_bold(nmbr.to_i,true)
						end
					end
					if spec.index("italics")
						self.style_set_italic(nmbr.to_i,true)
					end
				end
			end
		end
	
		def handle_goto
			res = get_number_from_user("Move your cursor to the line you want to goto.","Enter line number:","Goto line...",
				self.get_current_line(),1,self.get_line_count(),self)
			if res == -1
				return
			end
			self.goto_line(res-1)
			self.scroll_to_line(res-1)
		end
	
		def handle_find
			@find_data = FindReplaceData.new if @find_data.nil?
			flags = @find_data.get_flags
			@find_data.set_flags(flags | FR_DOWN)
			dlg_find = FindReplaceDialog.new(self,@find_data,"Find")
			dlg_find.show(true)
		end
	
		def handle_find_next
			ret = find()
			if !ret
				message_box("Unable to find #{@find_data.get_find_string}","Find",ID_OK|ICON_INFORMATION)
			end
		end
	
		def handle_find_prev
			flags = @find_data.get_flags
			if flags.has_style? FR_DOWN
				@find_data.set_flags(flags ^ FR_DOWN)
			else
				@find_data.set_flags(flags | FR_DOWN)
			end
			ret = find()
			@find_data.set_flags(flags)
			if !ret
				message_box("Unable to find #{@find_data.get_find_string}","Find",ID_OK|ICON_INFORMATION)
			end
		end
	
		def handle_find_replace
			@find_data = FindReplaceData.new if @find_data.nil?
			dlg_find = FindReplaceDialog.new(self,@find_data,"Replace",FR_REPLACEDIALOG)
			dlg_find.show(true)
		end
	
		private

		def find()
			flags = 0
			flags |= STC_FIND_WHOLEWORD if @find_data.get_flags.has_style? FR_WHOLEWORD
			flags |= STC_FIND_MATCHCASE if @find_data.get_flags.has_style? FR_MATCHCASE
			if @find_data.get_flags.has_style? FR_DOWN
				minPos = self.get_selection_end
				maxPos = self.get_text_length
			else
				minPos = self.get_selection_start
				maxPos = 0
			end
			i = find_text(minPos,maxPos,@find_data.get_find_string,flags)
			if i == STC_INVALID_POSITION
				return false
			end
			self.goto_pos(i)
			self.set_selection_start(i)
			self.set_selection_end(i+@find_data.get_find_string.length)
			return true
		end
		
		def on_find_dialog(evt)
			type = evt.get_event_type()
			case type
				when EVT_COMMAND_FIND
					ret = find()
					if !ret
						message_box("Unable to find #{@find_data.get_find_string}","Find",ID_OK|ICON_INFORMATION)
					end
				when EVT_COMMAND_FIND_NEXT
					ret = find()
					if !ret
						message_box("Unable to find #{@find_data.get_find_string}","Find",ID_OK|ICON_INFORMATION)
					end
				when EVT_COMMAND_FIND_REPLACE
					if self.get_selection_end - self.get_selection_start > 0 && self.get_selected_text == @find_data.get_find_string
						self.replace_selection(@find_data.get_replace_string)
						ret = find()
					else
						ret = find()
					end
					if !ret
						message_box("Unable to find #{@find_data.get_find_string}","Replace",ID_OK|ICON_INFORMATION)
					end
				when EVT_COMMAND_FIND_REPLACE_ALL
					if self.get_selection_end - self.get_selection_start > 0
						cur_pos = [self.get_selection_start,self.get_selection_end]
					else
						cur_pos = self.get_current_pos
					end
					flags = @find_data.get_flags
					@find_data.set_flags(flags |= FR_DOWN) unless flags.has_style? FR_DOWN
					nmbr_fnd = 0
					ret = true
					loop do
						ret = find
						if ret
							self.replace_selection(@find_data.get_replace_string)
							nmbr_fnd += 1
						else
							break
						end
					end
					if cur_pos.class == Array
						self.set_selection(*cur_pos)
						self.goto_pos(cur_pos[1])
					else
						self.goto_pos(cur_pos)
					end
					message_box("Replaced #{nmbr_fnd} instances of #{@find_data.get_find_string}","Replace",ID_OK|ICON_INFORMATION)
			end
		end
	
		def on_margin_click(evt)
			line_num = self.line_from_position(evt.get_position)
			margin = evt.get_margin
			if (margin == 1)
				self.toggle_fold(line_num)
			end
		end
	
		def on_update_ui(evt)
			if self.get_current_pos() > 0 and self.get_char_at(self.get_current_pos() -1).chr =~ /[\[{()}\]]/ and
				self.get_style_at(self.get_current_pos() - 1) == STYLE_OPERATOR
				start_match = self.get_current_pos() - 1
			elsif self.get_char_at(self.get_current_pos()).chr =~ /[\[{()}\]]/ and 
				self.get_style_at(self.get_current_pos()) == STYLE_OPERATOR
				start_match = self.get_current_pos()
			end
		
			if start_match
				match = self.brace_match(start_match)
				if match == STC_INVALID_POSITION
					self.brace_bad_light(start_match)
				else
					self.brace_highlight(start_match,match)
				end
			else
				self.brace_highlight(STC_INVALID_POSITION,STC_INVALID_POSITION)
			end	
		end
	
		def on_savepoint_reached(evt)
			if !@loading
				nb = self.get_parent
				main = nb.get_parent
				page = nb.get_page_index(self)
				nb.set_page_bitmap(page,main.instance_variable_get("@fbmp"))
				@modified = false
			end
		end
	
		def on_savepoint_left(evt)
# 			if !@loading
# 				nb = self.get_parent
# 				main = nb.get_parent
# 				page = nb.get_page_index(self)
# 				nb.set_page_bitmap(page,main.instance_variable_get("@fcbmp"))
# 				@modified = true
# 			end
		end	
	
		def on_charadded(evt)
			chr = evt.get_key
			curr_line = self.get_current_line
			if (chr == 13 || chr == 10)  # Windows Returns \r, Linux returns \n
				if curr_line > 0
					# Test Buffer for Indenting
					# Space is prepending to get proper resolution when something begins at
					# the begining of the line
					# Also need to ignore Comments
					line = " " + self.get_line(curr_line - 1)
					cindt = self.get_line_indentation(curr_line - 1)
					plindt = self.get_line_indentation(curr_line - 2) if curr_line > 1
					case line
						when /[\W^][\#]\s/
							cindt = cindt
						when /[\W^](=begin|=end)\s/
							self.set_line_indentation(curr_line -1,0)
						when /[\W^](class|def|case|module|do|while|for|begin)\s/
							cindt += 2
						when /[\W^](else|elsif|rescue|when)\s/
							if cindt >= plindt
								pl = curr_line > 1 ? self.get_line(curr_line-2) : ""
								if pl =~ /[\W^](class|def|case|module|do|while|for|begin|if|unless|else|elsif|rescue|when)\s/
									if cindt > plindt
										self.set_line_indentation(curr_line - 1,cindt-2)
									elsif cindt == plindt
										cindt += 2
									end
								else
									self.set_line_indentation(curr_line - 1,cindt-2)
								end
							end
						when /[\W^]end\s/
							if cindt >= plindt
								pl = curr_line > 1 ? self.get_line(curr_line-2) : ""
								if pl =~ /[\W^](class|def|case|module|do|while|for|begin|if|unless|else|elsif|rescue|when)\s/
									if cindt > plindt
										self.set_line_indentation(curr_line - 1,cindt-2)
										cindt -= 2
									end
								else
									self.set_line_indentation(curr_line - 1,cindt-=2)
								end
							end
						when /[\W^](if|unless)\s/
							srch = line.index("if").nil? ? "unless" : "if"
							i = line.index(srch)
							txt = false
							line[0..i-1].each_byte do |char|
								if char.chr =~ /^\w/
									txt = true
									break
								end
							end
							if !txt
								cindt += 2
							end
					end
					self.set_line_indentation(curr_line,cindt)
					self.goto_pos(self.get_line_end_position(curr_line))
				end
			end
		end
	
		def on_modified(evt)
# 			self.get_parent.get_parent.handle_notebook_change()
		end
		
		def on_key(evt)
			p evt.get_key()
			p evt.get_control()
			p evt.get_shift()
=begin
			if evt.get_key().chr == "\t"
				if evt.get_control()
			page = self.get_parent.get_current_selection()
=end
		end

		def get_file_name(path)
			if path.index("\\")
				i = path.rindex("\\")
				path[i+1..-1]
			else
				if path.index("/")
					i = path.rindex("/")
					path[i+1..-1]
				else
					path
				end
			end
		end
	
		def get_save_file()
			file = FileDialog.new(self,"Save file","","","Ruby Files (*.rb;*.rbw)|*.rb;*.rbw|All Files (*.*)|*.*",FD_SAVE|FD_OVERWRITE_PROMPT)
			ret = file.show_modal
			if ret == ID_CANCEL
				return
			end
			@name = get_file_name(file.get_path())
			@fname = file.get_path()
		end
	
		def get_saveas_file()
			file = FileDialog.new(self,"Save file as","","","Ruby Files(*.rb;*.rbw)|*.rb;*.rbw|All Files (*.*)|*.*",FD_SAVE|FD_OVERWRITE_PROMPT)
			ret = file.show_modal
			if ret == ID_CANCEL
				return ID_CANCEL
			end
			@name = get_file_name(file.get_path())
			@fname = file.get_path()
		end
	end
end
